package com.jihui.enterprise.web.common;

import com.jihui.account.boot.security.web.userdetails.YtxWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;

/**
 * web security config
 *
 * @author linux_china
 */
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class JihuiEnterpriseSecurityConfigurerAdapter extends YtxWebSecurityConfigurerAdapter {

    @Value("${info.account.login.url}")
    private String loginUrl;

    @Value("${info.buyer.domain}")
    private String buyerDomain;

    @Override
    protected void internalConfigure(HttpSecurity http) throws Exception {
        http.sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().authorizeRequests()
//                .antMatchers("/","/fragment/show").hasAnyRole("BUYER","ADMIN","OPERATOR")
                .antMatchers("/**").hasAuthority("ROLE_BUYER")
                .anyRequest().authenticated();
    }
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(whiteUrls);
    }
    public String getRedirect() {
        return null;
    }
}